import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from  ..items import *
"""
https://www.tupianzj.com/meinv/mm/meizitu/
目的 到这个网页 爬取图片保存到本地 
"""

class MvSpider(CrawlSpider):
    name = 'mv'
    allowed_domains = ['tupianzj.com']
    start_urls = ['https://www.tupianzj.com/meinv/mm/meizitu/']

    rules = (
        Rule(LinkExtractor(allow=r'/meinv/\d*/\d*.html'), callback='parse_item', follow=True),
    )
    def parse_item(self, response):
        item = MeiziItem()
        title=response.xpath('//*[@id="container"]/div/div/div[2]/h1/text()').get()
        # 在回调方法里面需要加上 属性数据
        link=response.xpath('//*[@id="bigpic"]/a[2]/img/@src').get()
        print(title)
        print(link)
        item["title"]=title
        item["link"]=link
        return item
